<template>
	<view class="" style="padding-bottom: 40rpx;">
		<view class="warp">
			<view class="header">
				<view class="search">
					<image class="icon" src="/static/images/search_icon.png" mode=""></image>
					<input class="input" v-model="keyword" type="text" value="" placeholder="请输入商品名称或关键字"/>
				</view>
				<view class="btn" @click="search">搜索</view>
			</view>
			
			<view class="banner_box">
				<swiper class="banner_swiper" :indicator-dots="true" :autoplay="true" :interval="5000" :duration="300" circular="true" indicator-color="#fff" indicator-active-color="#284179">
					<swiper-item v-for="item in bannerlist" :key="item.id">
						<view class="swiper-item"><image class="img" lazy-load :src="item.imgSrc" mode="aspectFill"></image></view>
					</swiper-item>
				</swiper>
			</view>
			<view class="nav_con">
				<view class="nav_list"  v-for="(item,index) in typelist" :key="item.id" @click="jumpTo('/pages/feilei/feilei?typeid='+item.id+'')" >
					<image class="n_img" :src="item.icon" mode=""></image>
					<view class="text">{{item.name}}</view>
				</view>
			</view>
		</view>
		<view class="notice">
			<image @click="gonggao" class="l_icon" src="../../static/images/notice_icon.png" mode=""></image>
			<view class="r_box">
				<swiper class="swiper" 
					:indicator-dots="false" 
					:autoplay="true" 
					:circular="true"
					:vertical="true"
					:disable-touch="true"
					:interval="3000" 
					:duration="500"
					>
					<swiper-item  v-for="item in notice" @click="msgdetail(item.id)" :key="item.id" >
						<view class="swiper-item">
							<view class="n_name" >{{item.title}}</view>
						</view>
					</swiper-item>
				</swiper>
			</view>
		</view>
		<view class="chanpin_con">
		<!-- 推荐 -->	
			<view class="bk_chanpin">
				<view class="top">
					<view class="left"  >
						<image class="l_img2" src = "/static/images/index_tuijian_30.png" mode=""></image>
						<view>平台新品</view>
					</view>
				</view>
			</view>
		</view>
		<view class="chanpin_con">	
			<view class="bk_chanpin">
				<view class="tj_list_">
					<view class="tj_list" v-for="item in good" :key="item.id"  @click="jumpTo('/pages/shangpin_xq/shangpin_xq?id='+item.id+'')"  >
						<image class="tj_img" :src="item.goodImgSrc" mode=""></image>
						<view class="title">{{item.goodName}}</view>
						<view class="tj_price">
							<view class="money"> 
								<image src="../../static/images/coin.png" class="coin" mode=""></image> 
								<view>{{item.goodNowPrice}}</view>
							</view>
							<view class="num">销量{{item.goodSaleNum}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<uni-load-more :loadingType="loadingType" :contentText="contentText"></uni-load-more>
	</view>
</template>

<script>
	import uniLoadMore from "@/components/uni-load-more.vue" 
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				loadingType: 0,
				contentText: {
					contentdown: "上拉显示更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多数据了"
				},
				bannerlist:[],
				typelist:[],
				notice:[],
				good:[],
				keyword:'',
				showtip:false,
				versonnum:0,
				p:1
			}
		},
		onShow() {
			
		},
		onLoad(options) {
			var token = uni.getStorageSync('token');
			if(token == '' || token ==0){
				uni.navigateTo({
					url:'/pages/login/login'
				})
				return;
			}
			uni.setNavigationBarTitle({
				title: '首页'
			});
			this.p=1;
			var that=this;
			this.$http.get('system/getBanner',{}).
			then(function (response) {
				that.bannerlist = response.data;
			}).catch(function (error) {
				console.log(error);
			});
				
			this.$http.get('system/getNews',{}).
			then(function (response) {
				that.notice = response.data;
			}).catch(function (error) {
				console.log(error);
			});
			
			this.$http.get('mall/getGoodCate',{}).
			then(function (response) {
				that.typelist = response.data;
			}).catch(function (error) {
				console.log(error);
			});
			this.getinfo();

			
		
			

		},
		methods: {
			
			gonggao(){
				uni.navigateTo({
					url:'/pages/gonggao/gonggao'
				})
			},
			jifen(){
				uni.navigateTo({
					url:'/pages/feilei/feilei?typeid=19'
				})
			},
			msgdetail(id){
				console.log(id);
				uni.navigateTo({
					url:'/pages/xiangqing/xiangqing?id='+id
				})
			},
			jumpTo(url){
				uni.navigateTo({
					url:url
				})
			},
			goodslist(id,limit,n){
				uni.request({
					url:this.weburl+'&c=shouye&a=goods',
					data:{
						id:id,
						limit:limit,
					},
					success: (res) => {
						var data = res.data.data	
						if(n==0){
							this.goods0 = data
						}else if(n==1){
							this.goods1 = data
						}else{
							this.goods2 = data
						}
						
					}
				})
			},
			search(){
				var key=this.keyword;
				if(key==''||key==undefined||key==null){
					uni.showToast({
						title:'请输入关键字',
						duration:15000,
						icon:'none'
					})
					return;
				}
				var key=encodeURIComponent(key);
				uni.navigateTo({
					url:'/pages/feilei/feilei?key='+key
				})
			},
			getinfo(){
				var that=this;
				this.$http.get('mall/getGoodList',{'page':that.p,'fromType':1}).
				then(function (response) {
					if(that.p==1){
						console.log(1);
						that.good=response.data;
					}else{
						console.log(2);
						that.good=that.good.concat(response.data);
					}
					that.p++;
					that.loadingType = 0;
				}).catch(function (error) {
					console.log(error);
				});
			}
		},
		//加载更多
		onReachBottom(){
			if (this.loadingType !== 0) {
				return;
			}
			this.getinfo();
		}
	}
</script>

<style>
	page{
		background-color: #f7f7f7;
	}
</style>
<style scoped lang="scss">
	.jifen{
		width: 100%;
		height:300rpx;
		display: flex;
		justify-content: center;
		.l_img2{
			display: block;
			width: 710rpx;
			height: 100%;
			border-radius: 10rpx;
		}
	}
	.coin{
		width:50rpx;
		height:50rpx;
	}
	.erweima{
		width:100%;
		height:100%;
		background-color: #000000;
		opacity: 0.9;
		position: fixed;
		top: 0;
		left:0;
		z-index: 10000;
		.erclose{
			
		}
	}
	.tip{
		position: fixed;
		background-color: #284179;
		top:96rpx;
		wdith:100%;
		height:48rpx;
		z-index: 99;
		.tipc{
			width:710rpx;
			height:40rpx;
			margin:4rpx 20rpx 0 20rpx;
			line-height: 40rpx;
			font-size: 28rpx;
			background-color:#000000;
			border-radius: 10rpx;
			opacity: 0.7;
			color:#FFFFFF;
			.tipbtn{
				width:300rpx;
				height:40rpx;
				line-height: 40rpx;
				border-radius: 10rpx;
				margin: 0rpx;
				display: block;
				text-align: center;
				float:left;
			}
			.close{
				float:right;
				margin-right:10rpx;
			}
		}
	}
	.warp{
		width: 100%;
		background-color: #ffffff;
		.header{
			background-color: #FFFFFF;
			height: 96rpx;
			width: 100%;
			background: url('~@/static/images/index_header_bg.jpg') no-repeat center;
			background-size: 100% 100%;
			top: 0;
			left: 0;
			padding: 0 20rpx;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			z-index: 99;
			.search{
				height: 70rpx;
				border-radius: 35rpx;
				background: #fff;
				flex: 1;
				display: flex;
				align-items: center;
				padding: 0 30rpx;
				.icon{
					display: block;
					width: 30rpx;
					height: 30rpx;
					margin-right: 20rpx;
				}
				.input{
					line-height: 70rpx;
					color: #a5a5a5;
					display: block;
					flex: 1;
					height: 70rpx;
					font-size: 26rpx;
				}
			}
			.btn{
				height: 70rpx;
				line-height: 70rpx;
				font-size: 28rpx;
				color: #fff;
				padding-left: 24rpx;
			}
		}
		.banner_box{
			height: 300rpx;
			width: 100%;
			background: url('~@/static/images/banner_bg.png') no-repeat left top;
			background-size: 100% 230rpx;
			.banner_swiper{
				height: 300rpx;
				.swiper-item{
					width: 100%;
					height:300rpx;
					display: flex;
					justify-content: center;
					.img{
						display: block;
						width: 710rpx;
						height: 100%;
						border-radius: 10rpx;
					}
				}
			}
		}
		.nav_con{
			background-color: #FFFFFF;
			padding: 0 20rpx 40rpx;
			display: flex;
			flex-wrap: wrap;
			.nav_list{
				margin-top: 40rpx;
				text-align: center;
				width: 25%;
				.n_img{
					width: 90rpx;
					height: 90rpx;
					border-radius: 50%;
				}
				.text{
					font-size: 24rpx;
					color: #454545;
				}
			}
		}
	}
	.chanpin{
		background-color: #FFFFFF;
		margin-top: 20rpx;
		padding: 0 20rpx;
		.pic{
			display: flex;
			flex-wrap: wrap;
			padding: 40rpx 0;
			.p_img{
				width: 345rpx;
				height: 180rpx;
				margin-right: 20rpx;
				&:nth-child(2n){
					margin-right: 0;
				}
			}
		}
	}
	.chanpin_con{
		margin-top: 20rpx;
		background-color: #ffffff;
		&:last-child{
			margin-top: 0;
		}
		.bk_chanpin{
			.top{
				background-color: #FFFFFF;
				margin-top: 20rpx;
				padding: 0 20rpx;
				display: flex;
				height: 110rpx;
				justify-content: space-between;
				.left{
					height: 110rpx;
					align-items: center;
					display: flex;
					font-size: 32rpx;
					color: #454545;
					.l_img{
						padding-right: 20rpx;
						width: 30rpx;
						height: 37rpx;
					}
					.l_img1{
						padding-right: 20rpx;
						width: 38rpx;
						height: 36rpx;
					}
					.l_img2{
						padding-right: 18rpx;
						width: 29rpx;
						height: 37rpx;
					}
				}
				.right{
					display: flex;
					height: 100rpx;
					align-items: center;
					font-size: 26rpx;
						color: #a5a5a5;
					.r_img{
						padding-left: 20rpx;
						width: 14rpx;
						height: 28rpx;
					}
				}
			}
			.sp_list_{
				padding: 0 20rpx 30rpx;
				.cp_list{
					padding: 30rpx 0;
					display: flex;
					border-bottom: 1px solid #ebebeb;
					&:last-child{
						border: none;
					}
					.cp_img{
						width: 250rpx;
						height: 180rpx;
						border-radius: 3px;
					}
					.cp_right{
						width: 430rpx;
						margin-left: 20rpx;
						.title{
							padding-top: 30rpx;
							color: #454545;
							font-size: 30rpx;
							white-space: nowrap;
							text-overflow: ellipsis;
							overflow: hidden;
						}
					}
					.cp_bottom{
						padding-top: 30rpx;
						height: 50rpx;
						align-items: center;
						justify-content: space-between;
						display: flex;
						font-size: 34rpx;
						color: #284179;
						.money{
							color: #284179;
							font-size: 28rpx;
							display: flex;
						}
						.num{
							color: #a5a5a5;
							font-size: 26rpx;
						}
					}
				}
			}
			.tj_list_{
				display: flex;
				flex-wrap: wrap;
				background-color: #f7f7f7;
				padding: 0 20rpx;
				.tj_list{
					margin-top: 20rpx;
					margin-right: 20rpx;
					width: 345rpx;
					background-color: #FFFFFF;
					&:nth-child(2n){
						margin-right: 0;
					}
					.tj_img{
						width: 345rpx;
						height: 310rpx;
						border-radius: 3px;
					}
					.title{
						padding: 0 20rpx;
						box-sizing: border-box;
						line-height: 60rpx;
						width: 345rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						font-size: 30rpx;
						color: #535353;
					}
					.tj_price{
						padding: 0 20rpx;
						display: flex;
						height: 60rpx;
						align-items: center;
						justify-content: space-between;
						.money{
							color: #284179;
							font-size: 32rpx;
							display: flex;
						}
						.num{
							color: #a5a5a5;
							font-size: 32rpx;
						}
					}
				}
			}
			.header_scroll{
				padding: 0 20rpx 30rpx;
				background: #fff;
				.scroll_x{
					white-space: nowrap;
					height: 100%;
					.list{
						padding-right: 20rpx;
						width: 240rpx;
						display: inline-block;
						align-items: center;
						.img{
							display: block;
							width: 230rpx;
							height: 160rpx;
							border-radius: 3px;
						}
						.text{
							line-height: 60rpx;
							width: 240rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
							font-size: 26rpx;
							color: #454545;
						}
						.xiaoliang{
							display: flex;
							height: 50rpx;
							align-items: center;
							justify-content: space-between;
							.money{
								font-size: 26rpx;
								color: #284179;
								display: flex;
							}
							.num{
								font-size: 26rpx;
								color: #a5a5a5;
							}
						}
					}
				}
			}
		}
	}
	.notice{
		height: 80rpx;
		display: flex;
		background: #fff;
		padding: 0 20rpx;
		align-items: center;
		.l_icon{
			display: block;
			width: 56rpx;
			height: 28rpx;
			margin-right: 32rpx;
		}
		.r_box{
			flex: 1;
			height: 80rpx;
			position: relative;
			padding-left: 40rpx;
			&::after{
				content: "";
				position: absolute;
				left: 0;
				top: 50%;
				transform: translateY(-50%);
				width: 1px;
				height: 26rpx;
				background: #e5e5e5;
			}
			.swiper{
				height: 80rpx;
				.swiper-item{
					font-size: 28rpx;
					color: #454545;
					line-height: 80rpx;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					.n_name{
						width: 580rpx;
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
					}
				}
			}
		}
	}
</style>
